package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.db.domain.MarketCollect;
import com.cskaoyan.market.db.domain.MarketCollectExample;
import com.cskaoyan.market.db.mapper.MarketCollectMapper;
import com.cskaoyan.market.service.AdminCollectService;
import com.cskaoyan.market.util.MybatisUtil;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class AdminCollectServiceImpl implements AdminCollectService {
    @Override
    public List<MarketCollect> list(String page, String limit, String sort, String order, String valueId, String userId) {
        SqlSession session = MybatisUtil.getSession();
        MarketCollectMapper mapper = session.getMapper(MarketCollectMapper.class);
        MarketCollectExample marketAddressExample = new MarketCollectExample();
        MarketCollectExample.Criteria criteria = marketAddressExample.createCriteria();
        if(!StringUtils.isEmpty(userId))
            criteria.andUserIdEqualTo(Integer.parseInt(userId));
        if(!StringUtils.isEmpty(valueId)) {
            criteria.andUserIdEqualTo(Integer.parseInt(valueId));
        }
        marketAddressExample.setOrderByClause(sort + " " + order);
        PageHelper.startPage(Integer.parseInt(page),Integer.parseInt(limit));
        List<MarketCollect> marketCollects = mapper.selectByExample(marketAddressExample);
        session.commit();
        session.close();
        return marketCollects;
    }
}
